const {getMusicUrl,handleStr} = require("../../utils/util")
Page({
  data: {
    music:[],
    offset:0,
  },
  onLoad :function(options){
    var music= [];
    var offset = this.data.offset;
    getMusicUrl(offset).then(res=>{
      this.handleHttpData(res,music);
      this.setData({music});
    })
  },
  onReachBottom:function(){
    var offset = this.data.offset;
    var music = this.data.music;
    offset+=20;
    getMusicUrl(offset).then(res=>{
      this.handleHttpData(res,music);
      this.setData({music,offset});
    })
  },
  handleHttpData(res,arr){
    res.data.albums.forEach(item=>{
      item.name = handleStr(item.name);
      arr.push(item);
    })
    return arr
  }
})